//????
#include "stm32f10x.h"
#include "./uart/myuart.h"
#include "./get_pulse_width/myget_pulse_width.h"  
#include "./tim_timer/tim_timer.h"
#include "./gpio/mygpio.h"

uint32_t timer;
int main(void)
{
	uint32_t time[4],i;
	GPIO_Config(GPIOC,GPIO_Pin_2,GPIO_Mode_Out_PP);
	GPIO_Config(GPIOC,GPIO_Pin_3,GPIO_Mode_Out_PP);
	uint32_t TIM_PscCLK = 72000000 / (71+1);
	DEBUG_USART_Config();
	
	TIMx_Up_Init(TIM6,(1000-1),71,NVIC_PriorityGroup_1,0,3);
	Catch_PWM_Init(TIM2,0X0F,GET_LOW,NVIC_PriorityGroup_1,0,4);
	
	printf ( "\r\nSTM32 begin\r\n" );
	while ( 1 )
	{	
		if ( timer == 2000 ) /* 1000 * 1 ms = 1s ??? */
    {
      timer = 0;    
			OUT_TOGGLE;
			OUT1_TOGGLE;			
    }
		for(i=0;i<4;i++)
		{
			if(TIM_ICUserValueStructure[i].Capture_FinishFlag == 1)
			{
				time[i] = TIM_ICUserValueStructure[i].Capture_Period * (0XFFFF+1) + 
							 (TIM_ICUserValueStructure[i].Capture_CcrValue+1);
				
				printf ( "\r\n%d%d%d%d%d time:%d.%d s\r\n",i,i,i,i,i,time[i]/TIM_PscCLK,time[i]%TIM_PscCLK );
				
				TIM_ICUserValueStructure[i].Capture_FinishFlag = 0;			
			}	
		}
		
						
	}
}
